package Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

class GenderException extends Exception{
    public GenderException(String msg){
        super(msg);
    }
}

public class Test_Exception {

    private String s_Gender;

    public String getS_Gender() {
        return s_Gender;
    }

    public void setS_Gender(String s_Gender) throws GenderException{
        if(s_Gender.equals("男") || s_Gender.equals("女")){
            this.s_Gender = s_Gender;
        }
        else{
            throw new GenderException("性别只能是男或者女！");
        }
    }

    //    public static void demo1() throws ParseException{
//        Scanner sc = new Scanner(System.in);
//        String dateStr = "21";
//        Date birthday = new Date();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        birthday = sdf.parse(dateStr);
//        System.out.println(birthday.toString());
//    }
//
//    public static void demo2() throws ParseException{
//        demo1();
//    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("输入学生性别");
        Test_Exception t = new Test_Exception();
        String gender = sc.next();
        try{
            t.setS_Gender(gender);
        } catch (GenderException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
//        try{
//            demo2();
//        }catch (ParseException e){
//            e.printStackTrace();
//            System.out.println(e.getMessage());
//        }
//        int[] nums = new int[] {1, 2, 3};
//        try{
////            nums = null;
//            System.out.println(nums[4]);
//            System.out.println("test");
//        }catch (Exception e){
//            System.out.println("数组越界！");
//            e.printStackTrace();
//            String s = e.getMessage();
//            System.out.println(s);
//        }


    }
}
